package com.itoffer.web;

import com.itoffer.pojo.Applicant;
import com.itoffer.pojo.ResumeBasicInfo;
import com.itoffer.service.ResumeService;
import com.itoffer.service.impl.ResumeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 添加简历信息servlet
 */

@WebServlet("/resumeAddServlet")
public class ResumeAddServlet extends HttpServlet {
    private ResumeService resumeService = new ResumeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String realname = req.getParameter("realname");
        String gender = req.getParameter("gender");
        String birthday = req.getParameter("birthday");
        String current_loc = req.getParameter("current_loc");
        String resident_loc  = req.getParameter("resident_loc");
        String telephone  = req.getParameter("telephone");
        String email  = req.getParameter("email");
        String job_intension  = req.getParameter("job_intension");
        String job_experience  = req.getParameter("job_experience");


        //封装对象
        ResumeBasicInfo basicInfo = new ResumeBasicInfo();
        basicInfo.setRealname(realname);
        basicInfo.setGender(gender);
        basicInfo.setBirthday(birthday);
        basicInfo.setCurrent_loc(current_loc);
        basicInfo.setResident_loc(resident_loc);
        basicInfo.setTelephone(telephone);
        basicInfo.setEmail(email);
        basicInfo.setJob_intension(job_intension);
        basicInfo.setJob_experience(job_experience);


        //System.out.println(basicInfo);

        HttpSession session = req.getSession();
        Applicant applicant =(Applicant) session.getAttribute("applicant");
        //System.out.println(applicant);
        //这里第二个参数为测试ID，后面修改为传过来的ID
        int i = resumeService.addResume(basicInfo, applicant.getApplicant_id());

        if(i>0){
            resp.setContentType("text/json;charset=utf-8");
            resp.getWriter().write("addSuccess");
        }else{
            resp.getWriter().write("addFail");
        }



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
